<template>
	<div class="home">
		
		<div>
			<el-button type="primary" @click="ledOpen()">开启LED</el-button>
			{{LED.text}}
		</div>
		
		当前版本{{version}}
	</div>
</template>

<script>
	let that,workerProcess
	import {
		mapGetters
	} from 'vuex'
	const {
		exec,
		spawn
	} = require('child_process');
	// const SerialPort = require('serialport')
	export default {
		computed: {
			...mapGetters(['size', 'version'])
		},
		components: {},
		name: 'Home',
		data() {
			return {
				LED:{
					text:'',
				}
			}
		},
		mounted() {
			that=this
			// SerialPort.list().then((ports)=>{
			// 	console.log(ports);
			// })
			// const port = new SerialPort('COM10', {
			// 	baudRate: 115200
			// })
			// //读取串口数据
			// port.on('readable', function () {
			// 	// console.log('Data:', port.read().toString('utf-8'))
			// })
			// // 将端口切换到“流动模式”
			// port.on('data', function (data) {
			//   console.log('Data:', data.toString())
			// })
			// port.on('error', function(err) {
			//   console.log('Error: ', err.message)
			// })
			// const buf = Buffer.from('我是一个buff');
			// adb shell factoryclient led open
			that.doSellFn('cmd');
			
		},
		methods: {
			//执行sell命令
			doSellFn(cmdStr) {
				workerProcess = exec(cmdStr)
				// 打印正常的后台可执行程序输出
				workerProcess.stdout.on('data', function(data) {
					console.log('stdout: ' + data.toString())
				})
				// 打印错误的后台可执行程序输出
				workerProcess.stderr.on('data', function(data) {
					console.log(data.toString('utf-8'))
				})
				// 退出之后的输出
				workerProcess.on('close', function(code) {
					console.log('out code：' + code)
				})
			},
			//开启led
			ledOpen(){
				workerProcess.stdin.write('adb shell factoryclient led open'+'\n');
			},
			doSellFn2(){
			}
			
		}
	}
</script>
<style scoped="scoped" lang="scss">
	.home {
		height: 100%;
	}

	.grid-content {
		margin-bottom: 15px;
	}
</style>
